#ifndef __WIFI_H__
#define __WIFI_H__

#include <rtthread.h>
#include <rtdevice.h>
#include <stdbool.h>

/* 调试标签定义 */
#define DBG_TAG "wifi"
#define DBG_LVL DBG_INFO
#include <rtdbg.h>

/* 网络状态标志 */
extern rt_bool_t network_available;
extern rt_bool_t mqtt_flag;
extern rt_bool_t mqtt_pub_in_progress;
extern rt_bool_t mqtt_pub_success;

/* WiFi配置参数 */
extern char ssid_str[64];
extern char pwd_str[64];

/* MQTT配置参数 */
extern const char *client_id;
extern const char *product_key;
extern const char *sign_params;
extern const char *server;
extern int port;
extern const char *topic;
extern const char *publish_topic;

/* 外部变量声明 */
extern rt_uint8_t temperature, temperature_x, humidity, humidity_x;
extern int up_period;
extern rt_thread_t mqtt_thread;
extern rt_uint8_t sw420_intensity;
extern int lat_int;     // 纬度整数部分
extern int lat_dec;     // 纬度小数部分(10000进制)
extern int lon_int;     // 经度整数部分
extern int lon_dec;     // 经度小数部分(10000进制)
extern int adc_data[3];
/* 函数声明 */
int uart4_init(void);
int send_at_and_check(const char *cmd, const char *expect, rt_uint32_t timeout_ms);
int check_wifi_state(void);
int reconnect_wifi(void);
int wifi_network_init(void);
int check_mqtt_conn_state(void);
int mqtt_network_init(void);
void check_network_status(void);
int publish_mqtt(const char *topic, const char *payload);
void mqtt_pub_thread(void *arg);
void at_flow_test(void);
void send_raw_at_command(void);
void send_raw(int argc, char **argv);
void mqtt_check(int argc, char **argv);
void wifi_check(int argc, char **argv);
int system_init(void);

#ifdef __cplusplus
}
#endif

#endif /* __WIFI_H__ */
